//
//  OutputMemoryStream.hpp
//  MultiPlayer
//
//  Created by 星落之尘 on 2020/6/10.
//  Copyright © 2020 Tan. All rights reserved.
//


#include "RoboCatPch.h"
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include <type_traits>

using namespace std;
class OutputMemoryStream
{
public:
    OutputMemoryStream():mBuffer(nullptr), mHead(0), mCapacity(0)
    {
        ReallocBuffer(32);
    }
    
    ~OutputMemoryStream()
    {
//        std::free(mBuffer);
        free(mBuffer);
    }
    
    
    
    const char* GetBufferPtr() const { return mBuffer;}
#if _WIN32
    uint32 GetLength() const {return mHead;}
#else
    u_int32_t GetLength() const {return mHead;}
#endif
    
    void Write(const void* inData, size_t inByteCount);

#if _WIN32
    void Write(uint32_t inData) { Write(&inData, sizeof(inData)); }
#else
    void Write(u_int32_t inData) { Write(&inData, sizeof(inData)); }
#endif
    void Write(int32_t inData) { Write(&inData, sizeof(inData)); }


private:
    void ReallocBuffer(u_int32_t inNewLength);
    
    char* mBuffer;
#if _WIN32
    uint32_t mHead;
    uint32_t mCapacity;
#else
    u_int32_t mHead;
    u_int32_t mCapacity;
#endif
};


